﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace HFK.DxFluentUI.Utility
{
  public class ReflectionHelper
  {
    public static  object GetPropertyValue(object o, string propertyName)
    {
      ChildPropertySyntax propertySyntax = new ChildPropertySyntax(propertyName);

      for (int i = 0; i < propertySyntax.Count; i++)
      {
        Type type = o.GetType();
        PropertyInfo propertyInfo = type.GetProperty(propertySyntax.Property(i));
        if (propertyInfo != null)
        {
          o = propertyInfo.GetValue(o, null);
        }
        else
        {
          return null;
        }
      }

      return o;
    }
  }
}
